package com.yuuzy.controller;

import com.yuuzy.constant.MessageConstant;
import com.yuuzy.result.Result;
import com.yuuzy.service.ImageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * 患者图片信息接口
 */
@RestController
@RequestMapping("/diagnose/image")
@Slf4j
@Api(tags = "患者图像信息接口")
public class ImageController {
    @Autowired
    private ImageService imageService;

    /**
     * 文件上传
     *
     * @param file
     * @return
     */
    @PostMapping("/upload/{id}")
    @ApiOperation("文件上传")
    public Result<String> upload(@PathVariable Integer id, MultipartFile file) {
        log.info("文件上传：{}", file);
        String filePath = imageService.upload(id,file);
        if (filePath == null) {
            return Result.error(MessageConstant.UPLOAD_FAILED);
        }
        else return Result.success(filePath);

    }
}
